package 剑指Offer;

public class Offer53II_0至n到1中缺失的数字 {
    public static void main(String[] args) {
        new Offer53II_0至n到1中缺失的数字().missingNumber(new int[]{0, 1, 3});
    }

    public int missingNumber(int[] nums) {
        int left = 0;
        int right = nums.length - 1;

        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] == mid) {//下标完整，缺失部分在右边
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        //终止条件是l = r + 1, 因此最终r在左，l在右，而切割线右边的l即为左边界
        return left;
    }
}
